/*  
     PlAr is Platform Arena: a 2D multiplayer shooting game
     Copyright (C) 2009 Ragagnin Antonio <spocchio@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package res.elements;


import java.awt.Point;
import java.util.ArrayList;

import plar.core.Action;
import plar.core.Common;
import plar.core.Element;
import plar.core.Shoot;
import plar.core.Parameters;
import plar.core.Sprite;


import plar.core.Player;

import java.awt.Rectangle;

import org.jbox2d.collision.AABB;
import org.jbox2d.collision.Shape;


public class Thorn extends Element {
	
	public Thorn()
	{
		//setProperty("lifeTime",200);
		//setProperty("explosionRelativeRectangle",new Rectangle(-150,-150,300,300));
		//setProperty("explosionDamage",40);
		setProperty("isActive", false);
		setProperty("isRunnable", true);
		setProperty("damage",100);
		setSize(0.5f,0.5f);
		actions.addAction("collision",new Action(){
		boolean base=false;		
				public Parameters call(Parameters parameters)

		{

			Element me = (Element) parameters.get("me");
			String subAction = (String) parameters.get("subAction");
			ArrayList<Element> collisions = (ArrayList<Element>) me.getProperty("collisionList");
			
			if(!base)
			{
				base=true;
				Element e = new Element();
		e.setSize(me.getSize().x,0.01f);
		
		e.setPosition(me.getPosition().x,me.getPosition().y+me.getSize().y);
		e.setStaticSprite("res/none.png");
		me.level.AddElement(e);
		//Common.info(2,"thorn created a basement!");
			}
			if (subAction == "main" ) {
				if (collisions != null)
				{
				
					for (Element e : collisions) {
						Common.info(2,"thorn collided");
						if (e.getProperty("type") == "player") {
							Common.info(2,"thorn collided with a player");
							Integer energy = (Integer) e.getProperty("energy");
							e.setProperty("energy", energy - (Integer)getProperty("damage"));
							Common.info(7,"shooted to:" + e);
						}
					}
				
				}
			}
			return null;
		
		}
			
		});
	}
}
	
